package com.OnTimeTeam.OnTime;

import java.io.File;

import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Environment;
import android.view.View;


public class UpdateDataOnFirstEntry extends AsyncTask<String, Void, Boolean> {
	View view;
	ProgressDialog  progressDialog;
    MainActivity host;
	
	public UpdateDataOnFirstEntry(MainActivity host) {
		this.host = host;
	}
	 
   
    protected void onPreExecute() {//Before
    	super.onPreExecute();

    	// prepare for a progress bar dialog
    	progressDialog = new ProgressDialog(host);
    	progressDialog.setCancelable(false);
    	progressDialog.setIcon(R.drawable.ic_launcher);
    	progressDialog.setMessage(host.getResources().getString(R.string.onTimeSmartAlarm));
    	progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    	progressDialog.show();
    }
    
    
    protected Boolean doInBackground(String... params) {//In Background

    	//Reload data!
    	host.reloadInfoOnFirstEntry();
    	
    	return true;
    }   
    
    protected void onPostExecute(Boolean result) {//After

    	progressDialog.dismiss();
    	
    	File wazeHistoryFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/waze/history");
    	if(wazeHistoryFile!= null && wazeHistoryFile.exists())
        	host.syncWithWazeAddresses();
    	
    }
	
    protected void onProgressUpdate(Void... values) {
    	
    	
    }
}

